//一般直接写在一个js文件中
layui.use(['element','form','layer','laytpl','laydate'],function () {
    var form = layui.form,
    layer = layui.layer,
        laytpl = layui.laytpl,
        laydate = layui.laydate;
    laydate.render({
        elem: '#endTime' //指定元素
    });

    //选择老人
    $("#elderlyName").on('click',function () {
        layer.open({
            type: 2,
            content: '/gbassessRecords/select/elderly',
            area: ['800px', '600px'],
            title:'选择老人',
            btn: ['确定 '],
            yes:function(index, layero){
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象
                var checkStatus = iframeWin.layui.table.checkStatus('mytable');
                if(checkStatus.data.length < 1 || checkStatus.data.length > 1){
                    iframeWin.layui.layer.msg("请选择一位老人");
                    return false;
                }
                var name = checkStatus.data[0].name;
                var id = checkStatus.data[0].id;
                var code = checkStatus.data[0].code;
                var idNo = checkStatus.data[0].idNo;
                $("#elderlyName").val(name);
                $("#elderlyId").val(id);
                $("#elderlyIdNo").val(idNo);
                //获取老人为付款的服务记录
                layer.close(index);
            }
        });
    });

    form.on('submit(formDemo)', function(data){
        if (data.field.selfEat != undefined && data.field.selfGarb != undefined && data.field.selfGoBed != undefined && data.field.selfToilet != undefined && data.field.selfWalk != undefined && data.field.selfLave != undefined){
            return true;
        }else{
            layer.alert("请先完成所有评估项目后再提交！");
            return false;
        }
    });

    $("#dy").on('click',function(){
        var $print = $("#print");
        $print.find(".hulve").hide();
        $print.jqprint();
        $print.find(".hulve").show();
    });
});
